<div class="modal-body">
	<form id="user-form" name="user-form" class="form-horizontal">
		<input type="hidden" name="optionId" id="optionId" value="">
		<input type="hidden" name="createTime" id="createTime" data-flag="date" data-format="yyyy-MM-dd HH:mm:ss">
		<input type="hidden" name="deviceid" id="deviceid" value="">
		
		<div class="zd-tab clearfix z1" style="margin-bottom:15px">
			<div id="modify_devices_tabs">
			</div>
		</div>
		
		<div class="box-body">
			<div class="col-md-12">
				<div class="form-group">
					<label for="warn_option" class="col-sm-2 control-label">预警项</label>
					<div class="col-sm-8">
						<select id="warn_option" class="form-control" name="warn_option">
								<option value="0" label="请选择预警项"/>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label for="warn_level" class="col-sm-2 control-label">预警级别</label>
					<div class="col-sm-8">
						<select id="warn_level" class="form-control" name="warn_level">
							<option value="蓝色" label="蓝色">蓝色</option>
							<option value="黄色" label="黄色">黄色</option>
							<option value="红色" label="红色">红色</option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label for="warn_value" class="col-sm-2 control-label">预警阀值</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" id="warn_value" name="warn_value" value=""/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">预警方式</label>
					<div class="col-sm-8">
						<div class="checkbox" >
							<label>
							<input type="checkbox" id="email" name="warn_type" value="E-MAIL"/>E-MAIL
							</label>
							<label style="margin-left:10px">
							<input type="checkbox" id="message" name="warn_type" value="短信"/>短信
							</label>
							<label style="margin-left:10px">
							<input type="checkbox" id="telephone" name="warn_type" value="电话"/>电话
							</label>
						</div>
					</div>
					
				</div>
				<div class="form-group">
					<label for="concactPerson" class="col-sm-2 control-label">通知人</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" id="concactPerson" name="concactPerson" value=""/>
					</div>
				</div>
			</div>
		</div>
		<!-- /.box-body -->
		<div class="box-footer text-right">
			<!--以下两种方式提交验证,根据所需选择-->
			<button type="button" class="btn btn-default" data-btn-type="cancel" onclick="dialog_close()">取消</button>
			<button id="btn_save" type="button" class="btn btn-primary" data-btn-type="save" onclick="save_batchModify()">提交</button>
		</div>
		<!-- /.box-footer -->
	</form>
</div>

<script type="text/javascript">
	var dataTimeType = "latest";//最新数据
	var Dtable_project = null;
	var dataType = null;
	//var station_type = null;
	var device = null;
	
	function loadModifyDevices( ids ){
		var param = {};
		if( ids != null ){
			param.search_station_ids = ids.split(",");
        }
		var json_data = JSON.stringify(param);
		var url = "../../tbl_station_info/list";
		$.ajax({
			url: url,
			type : 'post',
		    async : false,
			data: json_data,
			contentType: "application/json; charset=utf-8",
			dataType: "json",
			success: function( json ) {
				var html="";
				if( json.data ){
					$(json.data).each(function(){
						html += "<div class=\"device_tab device_tab_clicked\" style='margin-top:2px'>"+this.station_name+"</div>";
					});
					$("#modify_devices_tabs").html(html);
				}
			}
		});
	}
	
	//根据选择的设备类型加载预警项
	function loadWarnOptions( station_type ){
		var param = {};
		if( station_type != null ){
			param.station_type = station_type;
        }
		var json_data = JSON.stringify( param );
		var url = "../../tbl_station_warnoption/list";
		$.ajax({
			url: url,
			type : 'post',
		    async : false,
			data: json_data,
			contentType: "application/json; charset=utf-8",
			dataType: "json",
			success: function( json ) {
				$( "#warn_option" )[0].options.length = 0;
				if( json.data ){
					$(json.data).each(function(){
						$( "#warn_option" ).append("<option value='"+ this.id +"'>"+ this.optionname +"</option>");
					});
				}
			}
		});
	}
	
    $(document).ready(function(){
	    	//加载第一种类型数据所涉及到的设备信息
	    	loadModifyDevices( global.search_station_ids );
	    	loadWarnOptions( station_type );
    });
	
	function save_batchModify(){
		$("#btn_save").attr("disabled", true );
		if( $("#warn_value").val() == "" ){
			global.alert( "请填写预警阀值！" );
			$("#btn_save").attr("disabled", false );
			return false;
		}
		if( $("input[name='warn_type']:checkbox:checked").length == 0 ){
			global.alert( "请选择预警方式！" );
			$("#btn_save").attr("disabled", false );
			return false;
		}
		if( $("#concactPerson").val() == "" ){
			global.alert( "请填写预警通知人！" );
			$("#btn_save").attr("disabled", false );
			return false;
		}
		var warn_types = null;
		$("input[name='warn_type']:checkbox:checked").each(function(){
			if( warn_types == null ){
				warn_types = $(this).val();
			}else{
				warn_types += ","+ $(this).val();
			}
		});
		var station_warnconfig = {};
		station_warnconfig.deviceids = global.search_station_ids.split(",");
		station_warnconfig.optionid = $("#warn_option").val();
		station_warnconfig.optionname = $("#warn_option").find("option:selected").text();
		station_warnconfig.warn_level = $("#warn_level").val();
		station_warnconfig.v_warn_value = $("#warn_value").val();
		station_warnconfig.v_warn_type = warn_types;
		station_warnconfig.v_concact_person = $("#concactPerson").val();
		var json_data = JSON.stringify( station_warnconfig );
		var url = "../../tbl_station_warn_config/modify";
		$.ajax({
			  url: url,
			  type : 'post',
			  async : false,
			  data: json_data,
			  contentType: "application/json; charset=utf-8",
			  dataType: "json",
			  success: function(json) {
				 global.alert( json.message );
				 $("#station_info_main").load("warnsystem/warnconfig_list.html");
				 Dtable_station_warnconfig.ajax.reload();
				 dialog_close();
				 $("#btn_save").attr("disabled", false );
			  }
		});
	}
	
	function dialog_close(){
		global.dialog.close()
	}
</script>